/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By
 * Copyright authorization contact 18814114118
 */
package com.shop.cereshop.business.controller;


import com.shop.cereshop.business.annotation.NoRepeatSubmit;
import com.shop.cereshop.business.annotation.NoRepeatWebLog;
import com.shop.cereshop.business.page.shop.PlatformBusiness;
import com.shop.cereshop.business.param.shop.CommentParam;
import com.shop.cereshop.business.service.shop.CereShopCommentService;
import com.shop.cereshop.commons.domain.common.Page;
import com.shop.cereshop.commons.domain.user.CerePlatformUser;
import com.shop.cereshop.commons.exception.CoBusinessException;
import com.shop.cereshop.commons.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import  com.shop.cereshop.business.page.shop.ShopComment;
import javax.servlet.http.HttpServletRequest;

/**
 * 评论管理
 */
@RestController
@RequestMapping("comment")
/**
 * 注解方式生成日志对象，指定topic生成对象类名
 */
@Slf4j(topic = "CommentController")
@Api(value = "评论管理模块", tags = "评论管理模块")
public class CommentController {

    @Autowired
    private CereShopCommentService cereShopCommentService;

    /**
     * 查询所有评论（带分页）
     */
    @PostMapping("getAll")
    @ApiOperation("查询所有评论(已用)")
    public Result<Page<ShopComment>> getAll(@RequestBody CommentParam param) throws CoBusinessException {
        Page<ShopComment> page = cereShopCommentService.getAll(param);
        return Result.success(page);
    }

    /**
     * 根据ID查询详情
     */
    @PostMapping("getById")
    @ApiOperation("根据ID获取评论详情(已用)")
    public Result<ShopComment> getById(@RequestBody CommentParam param) throws CoBusinessException {
        ShopComment comment = cereShopCommentService.getById(param.getCommentId());
        return Result.success(comment);
    }

    /**
     * 新增评论
     */
    @PostMapping("reply")
    @NoRepeatSubmit
    @ApiOperation("商家回复parentId是回复的那条评论的id(已用)")
    @NoRepeatWebLog
    public Result add(@RequestBody ShopComment comment, HttpServletRequest request) throws CoBusinessException {
        PlatformBusiness user = (PlatformBusiness) request.getAttribute("user");
        cereShopCommentService.reply(comment, user);
        return Result.success();
    }

    /**
     * 修改评论
     */
    @PostMapping("update")
    @NoRepeatSubmit
    @ApiOperation("修改评论")
    @NoRepeatWebLog
    public Result update(@RequestBody ShopComment param, HttpServletRequest request) throws CoBusinessException {

        cereShopCommentService.update(param);
        return Result.success();
    }



}
